/**
 * @param {number} n
 * @return {string[][]}
 */
var solveNQueens = function(n) {
  if(n == 0)
    return [];
  if(n == 1)
    return [["Q"]];

  function transform(arr) {
    let result = [];
    for(let i = 0; i < arr.length; i++) {
      let str = "";
      for(let j = 0; j < n; j++) {
        if(arr[i] == j) {
          str = "Q";
        } else {
          str = ".";
        }
      }
      result.push(str);
    }
    return result;
  }

  function dfs(row) {
    if(row == n) {
      res.push(transform(stack));
      return ;
    }
    for(let j = 0; j < n; j++) {
      if(!col[j] && !main[row - j + n - 1] && !sub[row + j]) {
        // 加入该列的存放
        stack.push(j);
        // 设置为true，进行下一行的存放判定
        col[j] = true;
        main[row - j + n - 1] = true;
        sub[row + j] = true;
        dfs(row + 1);
        // 重置
        col[j] = false;
        main[row - j + n - 1] = false;
        sub[row + j] = false;
        // 删除该列的存放
        stack.splice(stack.length - 1, 1);
      }
    }
  }

  // 结果集
  let res = [], stack = [];

};
let n = 4;
console.log(solveNQueens(n));
n = 1;
console.log(solveNQueens(n));
